// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/unresolved/visitor.h>
#include <turbo/log/logging.h>

namespace cantor::unresolved {
    class UnresolvedMapArg;
    class UnresolvedTypeNameUri;
    class UnresolvedDictArg;
    class UnresolvedExprListArg;

    class UnresolvedUdfArg : public UnresolvedVisitor<UnresolvedUdfArg> {
    public:
        static constexpr const cantor::pb::ast::ExprNodeType TYPE = cantor::pb::ast::ExprNodeType::ENT_UDF_ARG;

        UnresolvedUdfArg(const cantor::pb::ast::UdfArg &node) : instance(node) {
        }

        ~UnresolvedUdfArg() override = default;

        const pb::Location &location_impl() const {
            return instance.location();
        }

        const pb::Status &error_status_impl() const {
            return instance.status();
        }

        bool has_uri() const {
            return instance.has_uri();
        }

        bool has_map_arg() const {
            return instance.has_map_arg();
        }

        bool has_dict_arg() const {
            return instance.has_dict_arg();
        }

        bool has_expr_list_arg() const {
            return instance.has_expr_list_arg();
        }

        cantor::pb::ast::ExprNodeType arg_type() const {
            return instance.arg_type();
        }

        bool empty_arg() const {
            switch (arg_type()) {
                case cantor::pb::ast::ENT_EXPR_LIST_ARG:
                    return !has_expr_list_arg();
                case cantor::pb::ast::ENT_MAP_ARG:
                    return !has_map_arg();
                case cantor::pb::ast::ENT_DICT_ARG:
                    return !has_dict_arg();
                default:
                    return true;
            }
            TURBO_UNREACHABLE();
        }


        UnresolvedTypeNameUri uri() const;

        UnresolvedMapArg map_arg() const;

        UnresolvedDictArg dict_arg() const;

        UnresolvedExprListArg expr_list_arg() const;

        const cantor::pb::ast::UdfArg &instance;
    };
} // namespace cantor::unresolved
